package com.soft.servlet;

import com.soft.entity.Order;
import com.soft.entity.OrderRefundRecord;
import com.soft.service.Domain;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author kongz
 * @version 1.0 2021/6/9 11:03
 * @description 退款申请
 */
@WebServlet(name = "TuiKuanRequestServlet", urlPatterns = "/TuiKuanRequest")
public class TuiKuanRequestServlet extends HttpServlet {
    private Domain domain;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        domain = new Domain();

        String orderId = req.getParameter("orderId");

        OrderRefundRecord ord = new OrderRefundRecord();
        ord.setOrderId(orderId);
        if (domain.getOrderById(Integer.parseInt(orderId)).getStatus() == Order.STATUS.STATUS_CLOSED)
            req.getSession().setAttribute("flag", 50);
        else if (domain.getOrderRefundRecordByOrderId(Integer.parseInt(orderId)) == null){
            if (domain.insertOrderRefundRecord(ord))
                req.getSession().setAttribute("flag", 47);
            else
                req.getSession().setAttribute("flag", 48);
        } else
            req.getSession().setAttribute("flag", 49);
        req.getRequestDispatcher("/OrderList").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
